﻿package ;

import php.Lib;
import php.Web;

/**
 * ...
 * @author 
 */

class Main 
{

	
	static function main() 
	{
		trace("Hello world!") ;
		var params = Web.getParams();
	
		 var cnx = php.db.Mysql.connect({ 

            user : "root",
            socket : null,
            port : 3306,
            pass : "",
			host : "127.0.0.1",
            database : "Users"
        });
		
		
		  var paramether = params.exists('act') ? params.get('act'): 'unknown_name';
			switch (paramether) {
				 case "del":
				var id = params.exists('id') ? params.get('id'): '2' ;
				var rset = cnx.request(" DELETE FROM User WHERE id = " + id + ";");
				php.Lib.print("delete user with id = "+ id + '<br>' );
				case "add":
				var name = params.exists('name') ? params.get('name'): 'unknown_name';
				var password = params.exists('password') ? params.get('password'): null;
				var city = params.exists('city') ? params.get('city'): 'unkmown_city';
				trace("added " +" " + " " +name + " " + password + "  " + city);
				var rset = cnx.request("INSERT INTO User VALUES ('0','"+name+"','"+password+"','"+city+"');");
				case "users":
				var rset = cnx.request("SELECT * FROM User;");
				php.Lib.print("Found " + rset.length + " users " + '<br>');
				for ( row in rset ) {
					php.Lib.print(row.id + " = User " + row.name + " password " + row.password + " city " + row.city+'<br>' );
					}
				default :
				php.Lib.print("BAD OPERATION");
				}
				cnx.close();
			}
		
		
		}
	

